package com.example.recyclerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {
    private List<itemdata> mitemdata = new ArrayList<>();
    private static MainActivity instance;
    ItemAdapts mItemAdapts;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        instance = this;//上下文
        intintest();//初始化数据
//        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);//将其实例化
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        //竖直方向
//        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        //水平方向
//     //   layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
//     //   GridLayoutManager layoutManager = new GridLayoutManager(this,3);
//        //设置item显示方法
//        recyclerView.setLayoutManager(layoutManager);
//        //将数据源传入到适配器里
//        ItemAdapt adapter = new ItemAdapt(mitemdata);
//        //显示item
//        recyclerView.setAdapter(adapter);
////        adapter.setOnItemClickListener(position -> {
////            Toast.makeText(this, "" , Toast.LENGTH_SHORT).show();
////        });

        RecyclerView recyclerView =  findViewById(R.id.recycler_view);//将其实例化
        mItemAdapts = new ItemAdapts(R.layout.item_test,mitemdata);
        mItemAdapts.setOnItemClickListener((adapter, view, position) -> {
            Log.e("TAG","");
        });
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        //启用动画
        mItemAdapts.setAnimationEnable(true);
        //设置动画方式
        mItemAdapts.setAnimationWithDefault(BaseQuickAdapter.AnimationType.SlideInRight);
        // rvDevice.addItemDecoration(new GridSpacingItemDecoration(spanCount, ScreenUtils.dip2px(this, 2), false));
        recyclerView.setAdapter(mItemAdapts);


    }

    /**
     * 初始化
     */
    public void intintest() {
        for (int i = 0; i < 10; i++) {
            itemdata item = new itemdata("W凯");
            mitemdata.add(item);
        }
    }
    public static MainActivity getInstance(){
        return instance;
    }
}